#include <iostream>
#include <memory>
#include "spdlog/spdlog.h"
#include "handler_base.h"
#include "socket_epoll.h"
#include "event.h"

using namespace simple;

class EchoHandler : public HandlerBase {
    std::string eventName() override {
        return "active";
    }

    void onEvent(Session *const session) noexcept override {
        std::string line = session->readerBuff()->readLine();
        if (!line.empty()) {
            spdlog::info("Received from xx msg: {}", line);
            session->writerBuff()->writeString(line);
            session->writerBuff()->flush();
        }
    }
};


int main() {
    EchoHandler process;
    Event::registerHandler(std::make_shared<EchoHandler>());

    SocketEpoll socketEpoll(8080, SOCK_STREAM);
    socketEpoll.ready();
    socketEpoll.accept();
}